package es.cea.agendatelefonica;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Anadir
 */
@WebServlet("/Anadir")
public class Anadir extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public Anadir() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		

		String nombre = request.getParameter("nombre");
		String telefono = request.getParameter("telefono");
		

		 List<ContactoTel> contactos = (List)request.getSession().getServletContext().getAttribute("contactos");
		 
		 
		 contactos.add(new ContactoTel(nombre, telefono));
		 
		 

		//publicar el modelo
			request.setAttribute("contactos", contactos);
			//seleccionar la vista
			request.getRequestDispatcher("anadir2.jsp")
			.forward(request, response);
			
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
